﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AdornerTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            my_inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
        }

        private void RadioButton_Click_1(object sender, RoutedEventArgs e)
        {
            //my_inkCanvas.EditingMode = InkCanvasEditingMode.Select;
            Matrix m = r1.RenderTransform.Value;
            m.ScaleAt(1.0, -1.0, 80, 90);
            r1.RenderTransform = new MatrixTransform(m);
        }

        private void my_inkCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            
        }

        private void my_inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e)
        {
            var sa = AdornerLayer.GetAdornerLayer(tbaa);
            sa.Add(new StrokeAdorner(tbaa));
        }
    }

    public class StrokeAdorner : Adorner
    {
        private readonly Rectangle _conerImg;
        public StrokeAdorner(UIElement uiElement)
            : base(uiElement)
        {
            _conerImg = new Rectangle
            {
                Fill = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("D:\\AA.png"))
                },
                Height = 40,
                Width = 40
            };
            AddVisualChild(_conerImg);
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            _conerImg.Arrange(new Rect(0, 0, 40.0, 40.0));
            return base.ArrangeOverride(finalSize);
        }
    }
}
